﻿-- =============================================
-- Author:		Andreas Könighofer (IT-eXperience)
-- Create date: 15.01.2009
-- Description:	Reads all resources that match with the given parameters
-- =============================================
CREATE PROCEDURE [dbo].[ReadResource]
	-- Add the parameters for the stored procedure here
	@ResourceID INT = NULL
	, @LocationID SMALLINT = NULL
	, @RessourceName NVARCHAR(100) = NULL
	, @SSNo NVARCHAR(50) = NULL
	, @MachineTypeID SMALLINT = NULL
	, @Status NVARCHAR(50) = NULL
	, @SerialNo NVARCHAR(50) = NULL
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT
	ResourceID,
	LocationID,
	RessourceName,
	SSNo,
	Resource.MachineTypeID,
	MachineType.MachineTypeName,
	Status,
	SerialNo
	FROM Resource LEFT OUTER JOIN MachineType ON Resource.MachineTypeID = MachineType.MachineTypeID
	WHERE ((@ResourceID IS NULL) OR (ResourceID = @ResourceID))
	AND ((@LocationID IS NULL) OR (LocationID = @LocationID))
	AND ((@RessourceName IS NULL) OR (RessourceName LIKE '%'+@RessourceName+'%'))
	AND ((@SSNo IS NULL) OR (SSNo LIKE '%'+@SSNo+'%'))
	AND ((@MachineTypeID IS NULL) OR (Resource.MachineTypeID = @MachineTypeID))
	AND ((@Status IS NULL) OR (Status LIKE '%'+@Status+'%'))
	AND ((@SerialNo IS NULL) OR (SerialNo LIKE '%'+@SerialNo+'%'))	
	
END

---- end script ReadResource stored procedure ----
---- end script read stored procedures ---------

---- start script update stored procedures -----
---- start script UpdateCustomer stored procedure ----

